Skip to content

Add ctx.isNewInstance for "save" hooks#515

Merged
bajtos merged 1 commit into
masterfrom
feature/isNewInstance
Mar 20, 2015
Merged

Add ctx.isNewInstance for "save" hooks#515
bajtos merged 1 commit into
masterfrom
feature/isNewInstance

Conversation

@bajtos

@bajtos bajtos commented Mar 19, 2015

Copy link
Copy Markdown
Member

"before save" hooks provide "ctx.isNewInstance" whenever "ctx.instance" is set. Possible values:

  • true for all CREATE operations
  • false for all UPDATE operations
  • undefined for "prototype.save"

"after save" hooks provide "ctx.isNewInstance" whenever "ctx.instance" is set. Possible values:

  • true after all CREATE operations
  • false after all UPDATE operations
  • undefined after "updateOrCreate" and "prototype.save"

Note: both "updateOrCreate" and "prototype.updateAttributes" don't provide ctx.instance to "before save" hooks, therefore ctx.isNewInstance it not provided either.

Connect to strongloop/loopback#838

/to @raymondfeng please review
/cc @fabien @clarkorz

Note that we will need to implement this feature in other connectors too, but unfortunately I don't have bandwidth for that now.

"before save" hooks provide "ctx.isNewInstance" whenever "ctx.instance"
is set. Possible values:
 - true for all CREATE operations
 - false for all UPDATE operations
 - undefined for "prototype.save"

"after save" hooks provide "ctx.isNewInstance" whenever "ctx.instance"
is set. Possible values:
 - true after all CREATE operations
 - false after all UPDATE operations
 - undefined after "updateOrCreate" and "save"

Note: both "updateOrCreate" and "prototype.updateAttributes"
don't provide `ctx.instance` to "before save" hooks, therefore
`ctx.isNewInstance` it not provided either.
@bajtos

bajtos commented Mar 20, 2015

Copy link
Copy Markdown
Member Author

I'll need to update this PR if #516 is landed first.

@fabien

fabien commented Mar 20, 2015

Copy link
Copy Markdown
Contributor

LGTM

@raymondfeng

Copy link
Copy Markdown
Contributor

LGTM.

As a general note, I don't like the fact that we overload the same property names for before save and after save. For example, for before save, ctx.isNewInstance denotes that an instance needs to be created, but for after save, ctx.isNewInstance indicates that an instance has been created.

I'm fine to land this PR as is and leave the general concerns to be addressed in future design refinements.

bajtos added a commit that referenced this pull request Mar 20, 2015
Add ctx.isNewInstance for "save" hooks
@bajtos
bajtos merged commit 84d538c into master Mar 20, 2015
@bajtos bajtos removed the #review label Mar 20, 2015
@bajtos
bajtos deleted the feature/isNewInstance branch March 20, 2015 17:33
@bajtos

bajtos commented Mar 20, 2015

Copy link
Copy Markdown
Member Author

@crandmck could you please update the "Operations hooks" docs page?

@crandmck

Copy link
Copy Markdown
Contributor

Added #526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants